
*** Results by TLF Component ***

do "$code_dir\calculate_q_values.do"
do "$code_dir\stack_results.do"

	
* modify variables
	
	preserve
	
	
	global addvars i.adjedu	 nothreat_m2_all
	
	
	duplicates drop id year, force
	drop  stu_id year_dose ward dob age resid male gender_miss white black hisp othrace race_miss lep_dv lep_miss sped_dv sped_miss frpl_dv frpl_miss homelang math_grdsubj math_std math_std_t math_pred math_resid read_grdsubj read_std read_std_t read_pred read_resid exp susp stonsitesusp stoffsitesusp stsusp mtsusp ltsusp suspdays membership_days absences totalexc_abs totalunexc_abs unexctruancy_abs absences_t

	gen p2_after_m2 = obsdate_2p > obsdate_2m
	gen m2_after_p2 = !p2_after_m2

	* just see overall score effects
	gen _newvar = -1 * haz_m2_totp
	reghdfe pr_2m i.m2_order _newvar pr_1p pr_1m $addvars if !posttest_m2, absorb(exp_capped sch1 step) vce(robust)
	reghdfe pr_2m i.m2_order _newvar pr_1p pr_1m $addvars if posttest_m2, absorb(exp_capped sch1 step) vce(robust)
	
	
	local nrows = 9
	local ncols = 1

	matrix pvalues1 = J(`nrows', `ncols', 0)
	matrix colnames pvalues1 = pval
	matrix pvalues2 = J(`nrows', `ncols', 0)
	matrix colnames pvalues2 = pval
	
	
	
	* new approach
	forval i = 1/9 {
		gen _newvar`i' = -1 * haz_m2_totp
		if `i' == 1 label var _newvar`i' "Lead well-organized, objective-driven lessons (1)"
		if `i' == 2 label var _newvar`i' "Explain content clearly (2)"
		if `i' == 3 label var _newvar`i' "Engage students at all learning levels in accessible and challenging work (3)"
		if `i' == 4 label var _newvar`i' "Provide students multiple ways to move toward mastery (4)"
		if `i' == 5 label var _newvar`i' "Check for student understanding (5)"
		if `i' == 6 label var _newvar`i' "Respond to student understanding - Scaffolding, probing, and re-teaching (6)"
		if `i' == 7 label var _newvar`i' "Develop higher-level understanding (7)"
		if `i' == 8 label var _newvar`i' "Maximize instructional time - pacing, student idleness and behavior (8)"
		if `i' == 9 label var _newvar`i' "Build a supportive, learning-focused classroom community (9)"
	
	
			if `i' != 6 {
				eststo m1`i': quiet reghdfe pr`i'_2m i.m2_order _newvar`i' pr`i'_1p pr`i'_1m $addvars if !posttest_m2, absorb(exp_capped sch1 step) vce(robust)
			}
			else {
				eststo m1`i': quiet reghdfe pr`i'_2m i.m2_order _newvar`i' pr`i'_1p pr`i'_1m i._miss_pr6_2m $addvars if !posttest_m2, absorb(exp_capped sch1 step) vce(robust)
			}
		
			matrix pvalues1[`i',1] = r(table)["pvalue","_newvar`i'"]
			
		}
		
		eststo m1F: 
		
		count if !posttest_m2
		local n_1 = r(N)
		count if posttest_m2
		local n_2 = r(N)
		
		* now generate the qvalues
		cap frame drop pvalues
		frame create pvalues 
		frame pvalues {
			svmat pvalues1, names(col)
			quietly: calc_q_values
			mkmat bky06_qval, mat(qvals1)
		}
		frame drop pvalues
		
		frame create pvalues 
		frame pvalues {
			svmat pvalues2, names(col)
			quietly: calc_q_values
			mkmat bky06_qval, mat(qvals2)
		}
		frame drop pvalues
		
	
	eststo combined_pre: appendmodels m11 m12 m13 m14 m15 m16 m17 m18 m19
	
	estimates restore combined_pre
	matrix q =  e(b)
	forval i=1/9 {
		local col = colnumb(matrix(q), "_newvar`i'")
		di `col'
		di q[1,`col']
		di qvals1[`i',1]
		matrix q[1,`col'] = qvals1[`i',1]
	}
	estadd matrix q
	estadd scalar new_n = `n_1'
	
	
	*
	esttab combined_pre using "$output_dir\Tables\\_Table_24_AllTLF_timecontrol_noPosttest.tex", keep(_newvar*) ///
		cells("b(${stars} fmt(%4.2fc) label(!))" "se(par fmt(%4.3fc) label(!))" "q(par(zz ww) fmt(%4.3fc)  label(!))") ///
		substitute(zz "[" qq " " ww "]" ! " " / "") gaps starlevels(\$^+\$ 0.10 * 0.05 ** 0.01 *** 0.001) nonotes ///
		label nodepvars eqlabels(none) mtitles("Pre-Test" "Post-Test") nolegend replace noobs scalar("new_n Observations")
	
	local symbol1 "o"
	local symbol2 "d"
		
	coefplot (m11 m12 m15 m14 m19, symbol(O) color(black) offset(0)) (m13  m16 m17 m18, symbol(D) color(gs13) offset(0)) , bylabel(Pre-Test) || ///
			, keep(_newvar* adjedu, relax) xline(0) nokey levels(95) xtitle(Effect of Reduced Monitoring) sort(1:) xsize(10in) ysize(5in)
	
	
	graph export "$output_dir\Figures\_Figure13_TLFChangeByStandard_timecontrol_noPosttest.png", replace width(1400) height(750)
	
	restore


	
	
	